home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
4_10.lha
/
4_10
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
51 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <stream.h>
ouble **mkarray(int rows, int cols);
nt matinv(double **A, double **I, int n);
oid prarray(double **a, int rows, int cols, char *name)
cout << "\n\n" << name << "\t(" << rows << " x " << cols << ")\n\n\n";
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cout << "\t" << a[i][j];
}
cout << "\n";
}
oid rdarray(double **a, int rows, int cols)
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
cin >> a[i][j];
ain()
int size;
cin >> size;
double **A = mkarray(size, size);
rdarray(A, size, size);
prarray(A, size, size, "A");
double **I = mkarray(size, size);
double **S = mkarray(size, size);
rdarray(S, size, size);
int ret = matinv(A, I, size);
if (ret == 0)
cout << "singular matrix!\n";
else
{
prarray(A, size, size, "A again");
prarray(I, size, size, "inverse");
prarray(S, size, size, "should be");
}
return 0;